﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Web.UI.WebControls.WebParts;
using QASPRibbon;
using QASPRibbon.Controls;
using QASPRibbon.MSOGallery;

namespace QASPRibbonDemo.MultiTabs
{
    [ToolboxItemAttribute(false)]
    public class MultiTabs : WebPart
    {
        protected override void CreateChildControls()
        {
            

            RibbonManager.Current.AddTabToPage(DemoSplit(), Page);
        }

        public RibbonTab DemoSplit()
        {
            var fontSizes = new[] { 2, 4, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 22, 26, 30, 42, 48, 56, 72 };
            // Define the tab
            var demoTab = new RibbonTab("DemoTab", "Demo Tab");
            // Define the group
            var demoGroup = new RibbonGroup("RibbonStrip", "Demo Group");
            demoTab.Groups = new []{demoGroup};
            var fonts = new InstalledFontCollection();

            #region FontFamily
            var ddlFontFamily = new RibbonDropDown("FontFamily", "Font")
                {
                    Width = 140,
                    Controls = new[]
                        {
                            new RibbonMenuSection("Theme", "Theme fonts")
                                {
                                    DisplayMode = RibbonMenuDisplayMode.Menu,
                                    Controls = new RibbonControl[]
                                        {
                                            new RibbonButton("Font1", "Calibri")
                                                {
                                                    Image = Gallery5.FontDialog
                                                },
                                            new RibbonButton("Font1", "Calibri Light")
                                                {
                                                    Image = Gallery5.FontDialog
                                                }
                                        }
                                },
                            new RibbonMenuSection("All", "All fonts")
                                {
                                    DisplayMode = RibbonMenuDisplayMode.Menu,
                                    Controls = fonts.Families.Select(f =>
                                                                     new RibbonButton(
                                                                         f.Name.Replace(" ", string.Empty), f.Name)
                                                                         {
                                                                             Image = Gallery5.FontDialog
                                                                         })
                                                    .OrderBy(b => b.Title)
                                                    .ToList()
                                }
                        }
                };
            #endregion
            #region FontSize
            var ddlFontSize = new RibbonDropDown("FontSize", "Font size")
                {
                    Width = 30,
                    Controls = new[]
                        {
                            new RibbonMenuSection("Size", string.Empty)
                                {
                                    DisplayMode = RibbonMenuDisplayMode.Menu,
                                    Controls = fontSizes
                                        .Select(f => new RibbonButton(f.ToString(), f.ToString()))
                                }
                        }
                };
            #endregion

            return new RibbonTab("Strip", "QASPRIBBON 15.3 Strip Demo Tab")
            {
                Groups = new []
                {
                    new RibbonGroup("group3", "Group")
                    {
                        Sections = new []
                        {
                            new RibbonGroupSection
                            {
                                DisplayMode = RibbonDisplayMode.Image16AndCaption,
                                Type = RibbonSectionType.TwoRows,
                                Alignment = RibbonSectionAlignment.Middle,
                                Controls = new RibbonControl[]
                                {
                                    new RibbonStrip
                                    {
                                        DisplayMode = RibbonDisplayMode.Image16AndCaption,
                                        Controls = new RibbonControl[]
                                        {
                                            ddlFontFamily,
                                            ddlFontSize
                                        }
                                    },
                                    new RibbonStrip
                                    {
                                        DisplayMode = RibbonDisplayMode.Image16Only,
                                        Controls = new RibbonControl[]
                                        {
                                            new RibbonToggleButton("b21", "b21")
                                            {
                                                Image = Gallery4.Bold
                                            },
                                            new RibbonToggleButton("b22", "b21")
                                            {
                                                Image = Gallery6.Italic
                                            },
                                            new RibbonFlyoutAnchor("f23", "f23")
                                            {
                                                Image = RibbonImageDefinition.Standard15(2,2),
                                                Controls = new []
                                                {
                                                    new RibbonMenuSection("ms", string.Empty)
                                                    {
                                                        DisplayMode = RibbonMenuDisplayMode.Menu,
                                                        Controls = new RibbonControl[]
                                                        {
                                                            new RibbonGallery("g", "g")
                                                            {
                                                                ElementDimensions = RibbonGalleryElementSize.Size190by30,
                                                                Controls = new []
                                                                {
                                                                    new RibbonGalleryButton("g1", "g1")
                                                                    {
                                                                        ElementDimensions = RibbonGalleryElementSize.Size190by30,
                                                                        ImageUrl = "http://www.westpoint.edu/caldol/SiteAssets/aboutCCL/images/doubleUnderline.gif"
                                                                    }
                                                                }
                                                            } 
                                                        }
                                                    },
                                                    new RibbonMenuSection("ms2", string.Empty)
                                                    {
                                                        DisplayMode = RibbonMenuDisplayMode.Menu16,
                                                        Controls = new RibbonControl[]
                                                        {
                                                            new RibbonButton("g2b1", "More underlines..."),
                                                            new RibbonFlyoutAnchor("g2b2", "Underline color")
                                                            {
                                                                Image = Gallery8.ShapeFillColorPickerClassic,
                                                                Controls = new []
                                                                {
                                                                    new RibbonMenuSection("s1", string.Empty)
                                                                    {
                                                                        DisplayMode = RibbonMenuDisplayMode.Menu16,
                                                                        Controls = new RibbonControl[]
                                                                        {
                                                                            new RibbonButton("b1", "Automatic")
                                                                            {
                                                                                Image = Gallery4.AppointmentColor3
                                                                            }
                                                                        }
                                                                    },
                                                                    new RibbonMenuSection("s2", "Theme colors")
                                                                    {
                                                                        DisplayMode = RibbonMenuDisplayMode.Menu,
                                                                        Controls = new[]
                                                                        {
                                                                            new RibbonColorPicker("picker")
                                                                            {
                                                                                Colors = RibbonColorPicker.StandardColors
                                                                            }
                                                                        }
                                                                    },
                                                                    new RibbonMenuSection("s3", "Standard colors")
                                                                    {
                                                                        DisplayMode = RibbonMenuDisplayMode.Menu,
                                                                        Controls = new[]
                                                                        {
                                                                            new RibbonColorPicker("picker")
                                                                            {
                                                                                Colors = new []
                                                                                    {
                                                                                        new RibbonColor(Color.DarkRed), 
                                                                                        new RibbonColor(Color.Red), 
                                                                                        new RibbonColor(Color.Orange), 
                                                                                        new RibbonColor(Color.Yellow), 
                                                                                        new RibbonColor(Color.LightGreen), 
                                                                                        new RibbonColor(Color.Green), 
                                                                                        new RibbonColor(Color.LightBlue), 
                                                                                        new RibbonColor(Color.Blue), 
                                                                                        new RibbonColor(Color.DarkBlue), 
                                                                                        new RibbonColor(Color.Purple)
                                                                                    }
                                                                            }
                                                                        }
                                                                    } 
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }, 
                                            new RibbonToggleButton("b23", "b21")
                                            {
                                                Image = Gallery6.FormatCellsFontDialog
                                            },
                                            new RibbonToggleButton("b24", "b21")
                                            {
                                                Image = Gallery8.RunThisForm
                                            },
                                            new RibbonToggleButton("b25", "b21")
                                            {
                                                Image = Gallery9.TableFind
                                            },
                                            new RibbonToggleButton("b26", "b21")
                                            {
                                                Image = Gallery9.ViewsFormView
                                            }
                                        }
                                    },
                                    new RibbonStrip
                                    {
                                        DisplayMode = RibbonDisplayMode.Image16Only,
                                        Controls = new RibbonControl[]
                                        {
                                            new RibbonButton("OpenInfopathForm", "OpenInfopathForm")
                                            {
                                                Image = Gallery6.FontSizeIncrease
                                            },
                                            new RibbonButton("OpenInfopathForm", "OpenInfopathForm")
                                            {
                                                Image = Gallery6.FontSizeDecrease
                                            }
                                        }
                                    },
                                }
                            }
                        }
                    } 
                }
            };
        }

        public RibbonTab Bee1()
        {
            var tab = new RibbonTab("Bee1", "Система блокировки абонентов")
            {
                Sequence = 1001,
                Groups = new[]
                {
                    new RibbonGroup("Group1", "SubLock")
                    {
                        Sections = new[]
                        {
                            new RibbonGroupSection
                            {
                                Type = RibbonSectionType.OneRow,
                                Controls = new RibbonControl[]
                                {
                                    new RibbonButton("Insert", "Ввод абонентов")
                                    {
                                        Image = RibbonImageDefinition.Standard15(3, 10)
                                    },
                                    new RibbonButton("Search", "Поиск")
                                    {
                                        Image = RibbonImageDefinition.Standard15(2, 11),
                                        OnClientClick = "var options = {url: '/_layouts/15/qaspribbondemo/search.aspx'}; SP.UI.ModalDialog.showModalDialog(options);"
                                    },
                                }
                            },
                            RibbonGroupSection.Divider,
                            new RibbonGroupSection
                            {
                                Type = RibbonSectionType.OneRow,
                                Controls = new RibbonControl[]
                                {
                                    new RibbonMRUSplitButton("Export", "Экспорт")
                                    {
                                        Image = RibbonImageDefinition.Standard15(3, 0),
                                        InitialItem = "PDF",
                                        Controls = new[]
                                        {
                                            new RibbonMenuSection("Root", "Экспорт")
                                            {
                                                DisplayMode = RibbonMenuDisplayMode.Menu32,
                                                Controls = new RibbonControl[]
                                                {
                                                    new RibbonButton("PDF", "Adobe PDF")
                                                    {
                                                        Image = new RibbonImageDefinition
                                                        {
                                                            Url32 = "/_layouts/15/images/bee/icon_pdf.png"
                                                        }
                                                    },
                                                    new RibbonButton("Word", "Microsoft Word")
                                                    {
                                                        Image = new RibbonImageDefinition
                                                        {
                                                            Url32 = "/_layouts/15/images/bee/icon_docx.png"
                                                        }
                                                    },
                                                    new RibbonButton("Excel", "Microsoft Excel")
                                                    {
                                                        Image = new RibbonImageDefinition
                                                        {
                                                            Url32 = "/_layouts/15/images/bee/icon_xlsx.png"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            return tab;
        }

        private string[] _demoArray = new[]
            {
                "John H Hammergren", "Ralph Lauren", "Michael D Fascitelli",
                "Richard D Kinder",
                "David M Cote", "George Paz", "Jeffery H Boyd"
            };

        private string[] _presidents = new []
            {
                "Abraham Lincoln",
                "James Buchanan",
                "James Monroe",
                "James Polk",
                "John Quincy Adams",
                "Martin Van Buren"
            };

        private IEnumerable<RibbonGalleryButton> _demoGalleryButtons()
        {
            return _presidents.Select(x => new RibbonGalleryButton(x.Replace(" ", string.Empty), x)
                {
                    ImageUrl = "/_layouts/15/images/ribbon/" + x.Replace(' ', '-') + "-128.png",
                    OnClientClick = "alert('" + x + " has been clicked!');",
                    Enabled = true,
                    ElementDimensions = RibbonGalleryElementSize.Size96by96
                });
        }

        private IEnumerable<RibbonGalleryButton> _demoGalleryButtons2()
        {
            return _presidents.Select(x => new RibbonGalleryButton(x.Replace(" ", string.Empty), x)
            {
                ImageUrl = "/_layouts/15/images/ribbon/" + x.Replace(' ', '-') + "-32.png",
                OnClientClick = "alert('" + x + " has been clicked!');",
                Enabled = true,
                ElementDimensions = RibbonGalleryElementSize.Size32by32
            });
        }

        private IEnumerable<RibbonButton> _demoButtons2()
        {
            return _presidents.Select(x => new RibbonButton(x.Replace(" ", string.Empty), x)
            {
                Image = new RibbonImageDefinition
                {
                    Url32 = "/_layouts/15/images/ribbon/" + x.Replace(' ', '-') + "-32.png"
                },
                OnClientClick = "alert('" + x + " has been clicked!');"
            });
        }

        private Random rnd = new Random();

        private IEnumerable<RibbonControl> _demoButtons()
        {
            return _demoArray.Select(x => new RibbonButton(x.Replace(" ", string.Empty), x)
            {
                Image = RibbonImageDefinition.Standard15(rnd.Next(5, 10), rnd.Next(5, 10)),
                OnClientClick = "alert('" + x + " has been clicked!');"
            }).Cast<RibbonControl>().ToArray();
        }
    }
}
